function TD_count(){
	setTimeout(function(){
		zeai.ajax({url:'tg_my'+zeai.ajxext+'submitok=ajax_TD_count1'},function(e){rs=zeai.jsoneval(e);
			var TG_NUM1V=rs.XX['num1'],TG_NUM2V=rs.XX['num2'],TG_NUM3V=rs.XX['num3'];
			setTimeout(function(){TG_NUM1.html(TG_NUM1V);},100);
			setTimeout(function(){TG_NUM2.html(TG_NUM2V);},200);
			setTimeout(function(){TG_NUM3.html(TG_NUM3V);},300);
		});
	},200);
}	
function TG_MSGFn(){
    zeai.listEach(zeai.tag(TG_MSGbox,'dt'),function(dt){
		var tid=dt.getAttribute("tid");
        var dd=dt.nextElementSibling;
		var dl=dt.parentNode,del=dl.lastElementChild;
        dd.onclick=function(){
			var b=dt.children[1];
			if(!zeai.empty(b)){
				b.remove();
				var tipnum=parseInt(tg_num_btm.innerHTML);
				if(tipnum>1){
					tg_num_btm.html(tipnum-1);	
				}else{
					tg_num_btm.remove();
				}
			}
			zeai.openurl('tg_my'+zeai.ajxext+'submitok=TG_MSG_detail&tid='+tid);
        }
		TG_MSGtouchDel(dl,dd);
		del.onclick = function(){dl.remove();zeai.ajax({url:'tg_my'+zeai.ajxext+'submitok=ajax_MSG_del',data:{tid:tid}});}
    });
}
function TG_MSGtouchDel(dl,dd) {
	var x,xy;
	function mstart(e){x = e.changedTouches[0].clientX;}
	function mmove(e){dlreset();
		var endx = e.changedTouches[0].clientX;
		xy = x - endx;
		if( xy > 30){ZeaiM6.fade({arr:[dl],num:'-7rem'});
		}else if( xy < -1){ZeaiM6.fade({arr:[dl],num:'0'});}
	}
	dd.addEventListener('touchstart',mstart);
	dd.addEventListener('touchmove',mmove);	
	function dlreset(){zeai.listEach(zeai.tag(TG_MSGbox,'dl'),function(dl){ZeaiM6.fade({arr:[dl],num:'0'});});}
}

/*v7新增*/
var p;
var zeaiLoadBack;
var cleandsj;
var ZeaiM6={
	zindex:1,
	page:{
		curpage:'',
		load:function(url,backName,curName){
			var go1='ZEAIGOBACK-'+curName,ZeaiPstack=getZeaiPstack();
			if(ZeaiPstack.length>0){for(var k=0;k<ZeaiPstack.length;k++){if(ZeaiPstack[k].id==go1)return false;	}}	
			if (typeof(url) == "object"){var data = url,form = url.form,url = url.url;}
			var postjson = {'url':url};
			if(!zeai.empty(form))Object.assign(postjson,{form:form});
			if(!zeai.empty(data))Object.assign(postjson,{data:data.data});
			zeai.ajax(postjson,function(e){
				var rs;
				if(zeai.empty(e)){
					rs=zeai.jsoneval(JSON_ERROR);zeai.msg(rs.msg);
				}else if(zeai.str_len(e)<200 ){//中断提示，不能输出内容flag!=1，判断逻辑在load页面
					if (e.indexOf("openurl") != -1){
						ZeaiM6.eval(e);
					}else{
						ZeaiM.sorry(zeai.jsoneval(e),backName);
					}
				}else{
					
					ZeaiM6.dojsFunc(e,function(e){loadPage(e);});
					function loadPage(e){
						
						ZeaiM6.curpage=curName;//for jump
						bkMw1 = (backName == ZEAI_MAIN)?-40:-140;
						setTimeout(function(){if (!zeai.empty(o(backName)))o(backName).css('transform:translate('+bkMw1+'%)');},100);
						//暗
						ZeaiM6.zindex++;
						var M=zeai.addtag('div');M.class('mask1 alpha0_100');M.id='M'+backName;M.style.zIndex=ZeaiM6.zindex;
						if(backName == ZEAI_MAIN){
							if (!zeai.empty(o('Mmain'))){o('Mmain').remove();}document.body.append(M);M.style.zIndex=1;
						}else{if (!zeai.empty(o(backName)))o(backName).append(M);}
						//暗束
						//头尾
						if (backName == ZEAI_MAIN)ZeaiM6.fade({arr:zeaiLoadBack,num:bkMw1+'%',dely:110});
						//头尾束
						var nameDOM = Zeai_cn__PageBox.append('<div id="' + curName + '" class="zeai-body">' + e + '</div>');
						setTimeout(function(){nameDOM.css('z-index:'+ZeaiM6.zindex+';transform:translate(-100%)');},50);ZeaiM6.eval(e);
						var curNameO=o('ZEAIGOBACK-'+curName);
						if (!zeai.empty(curNameO)){
							curNameO.onclick = function(){ZeaiM6.page.back(backName,curName);}
							history.pushState({btn:'WWW_ZEAI_CN__GOBACK'},'',null);
						}
					}
				}
			});
		},
		back:function(backName,curName){
			ZeaiM6.curpage=backName;//for jump
			dom = o(curName);
			bkMw2 = (backName == ZEAI_MAIN)?0:-100;
			if (!zeai.empty(o(backName)))o(backName).css('transform:translate('+bkMw2+'%)');
			//头尾
			if (backName == ZEAI_MAIN)ZeaiM6.fade({arr:zeaiLoadBack,num:bkMw2+'%'});
			//头尾束
			//暗
			var MbackName=o('M'+backName);
			if(!zeai.empty(MbackName)){MbackName.removeClass('alpha0_100');MbackName.addClass('alpha100_0');ZeaiM6.zindex--;}
			//暗束
			if(!zeai.empty(dom))dom.style.webkitTransform = 'translate(0)';
			setTimeout(function(){
				if(!zeai.empty(o(curName))){o(curName).remove();}
				//暗
				if (!zeai.empty(o('M'+backName))){o('M'+backName).remove();}
				//暗束
			},300);
			clearInterval(cleandsj);
		},
		jump:function(url,pageName){
			if (url=='main'){
				o(url).css('transform:translate(0%)');
					//暗淡
					if (!zeai.empty(o('Mmain'))){o('Mmain').remove();}
					//暗淡结束
				Zeai_cn__PageBox.html('');
				o(nav).css('transform:translate(0%)');
				return;
			}
			blankpage.show();
			o(ZeaiM6.curpage).css('transform:translate(0%)');
			o(ZEAI_MAIN).hide();
			setTimeout(function(){
				Zeai_cn__PageBox.html('');
				ZeaiM6.page.load(url,ZEAI_MAIN,pageName);
			},200);
			setTimeout(function(){blankpage.hide();},888);
		},
		onclk:function(json){
			var ZminiEtabAmenuI_cn=zeai.tag(json.obj,'i')[0];
			zeai.listEach(zeai.tag(json.obj,'li'),function(li){li.removeClass('ed');});
			json.li.addClass('ed');
			var span = json.li.getElementsByTagName("span")[0],iL,iW;
			if(json.kind=='block'){
				iL = json.li.offsetLeft;
				iW = json.li.offsetWidth;
			}else{
				iL = span.offsetLeft;
				iW = span.offsetWidth;
			}
			ZminiEtabAmenuI_cn.css('width:'+iW+'px;transform:translate('+iL+'px)');
		}
	},

	dojsFunc:function(e,fn){
		var jsF = [],m=0,n=0;
		var es = e.match(/<script src=[\w\W]+?><\/script>/ig);
		if(es) {
			for (var i in es) {
				str = es[i];
				if (typeof str == 'string'){
					jsF.push(str.match(/<script .*?src=\"(.+?)\"/)[1]);
					e = e.replace(str,'');m++;
				}
			}
		}
		//console.log('m='+m);
		if (m>0){
			return srcJsFile();
		}else{
			return fn(e);
		}
		function srcJsFile(){
			var q=0;
			for (var i in jsF) {
				srcjs = jsF[i];
				if (typeof srcjs == 'string'){
					q++;
					//console.log('srcjs='+srcjs);
					var head = document.getElementsByTagName('head')[0].innerHTML;
					if (head.indexOf(srcjs) == -1){
						loadJs(srcjs,function(){
								n++;
								if (n==m){
									//console.log('m=n');
									fn(e);return;
								}
							}
						);
					}else{
						//console.log('(srcjs) != -1'+'|            q='+q+'|m='+m);
						if (q==m)fn(e);
					}
				}
			}
		}
	},
	eval:function(e){
		var eJs = /<script(.|\n)*?>(.|\n|\r\n)*?<\/script>/ig;
		var eJsed = e.match(eJs);
		if(eJsed) {
			var regjs = /<script(.|\n)*?>((.|\n|\r\n)*)?<\/script>/im;
			for(var j=0;j<eJsed.length;j++){
				var jsV = eJsed[j].match(regjs);
				if(jsV[2]){if(window.execScript) {window.execScript(jsV[2]);}else{window.eval(jsV[2]);}}
			}
		}	
	},
	fade:function(json){
		if (!zeai.empty(json.arr)){
		for(var pg=0;pg<json.arr.length;pg++){
			(function(pg){
				if (zeai.ifint(json.delay)){setTimeout(set,json.delay);}else{set();}
				function set(){o(json.arr[pg]).css('transform:translate('+json.num+')');}
			})(pg);
		}}
	}
}
function page(json){var y=(zeai.empty(json.y))?ZEAI_MAIN:json.y;ZeaiM6.page.load(json.g,y,json.l);}
function loadJs(src, callback) {
    var script = document.createElement('script'),
	head = document.getElementsByTagName('head')[0];
	var h=head.innerHTML;
	if (h.indexOf(src) == -1){
		script.src = src;
		if (script.addEventListener) {
			script.addEventListener('load', function () {
			   callback();
			}, false);
		} else if (script.attachEvent) {
			script.attachEvent('onreadystatechange', function () {
				var target = window.event.srcElement;
				if (target.readyState == 'loaded') {
				   callback();
				}
			});
		}
		head.appendChild(script);
	}
}


window.addEventListener("popstate",function(){
	if(zeai.empty(location.hash)){
		var Zeai_cn__PageBox=o('Zeai_cn__PageBox');
		if(!zeai.empty(Zeai_cn__PageBox)){
			var goback=getZeaiPstack();
			goback = goback[goback.length-1];
			if(!zeai.empty(goback))goback.click();
		}
		if(!zeai.empty(o('iosMask'))){o('iosMask').click();}
		if(!zeai.empty(o('divBtmMod'))){o('divBtmMod').click();}
	}
});
function getZeaiPstack(){return document.querySelectorAll(".goback");}
if(mobkind()=="ios" && is_h5app()){
	//当页面加载状态改变的时候执行function
	document.onreadystatechange = function(){ 
		if(document.readyState == "complete"){//当页面加载状态为完全结束时进入 
			var thisweb=plus.webview.currentWebview();
			thisweb.setJsFile('_www/zeai.append.js');
	    }
	}
}
